//
//  ZRMainNavViewController.swift
//  XJ8XWB
//
//  Created by 中二 on 2016/10/23.
//  Copyright © 2016年 中二. All rights reserved.
//

import UIKit

class ZRMainNavViewController: UINavigationController , UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        interactivePopGestureRecognizer?.delegate = self
        
    }
    
    @objc private func backClick(){
        
        popViewController(animated: true)
        
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        var title:String
        
        if childViewControllers.count>0 {
            
            title = "返回"
            
            if childViewControllers.count == 1{
            
            title = childViewControllers.first?.title ?? ""
            
        }
            
                        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightedImgName: "navigationbar_back_withtext", title: title, target:  self, action: #selector(backClick))
            
        }
        
        super.pushViewController(viewController, animated: animated)
        
    }
    
    // 如果是首页的话 然后用户又向右侧滑动 然后在点击 push 不能完成
    // 默认如果不实现 返回的均为 true
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        // 如果. count == 1 就代表你已经到首页了 不能在滑动了
        return childViewControllers.count != 1
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
